// pass: 
function maxSubStrLength(charList, s) {
    let max = 0;
    let n = s.length;

    let dp = Array.from(new Array(n), _ => new Array(n).fill(0));

    let helper = function (string, newChar) {
        if (charList.includes(newChar)) {
            let count = 0;
            string += newChar;
            for (let i = 0; i < string.length; i++) {
                if (string[i] === newChar) count++
            }
            if (count % 2 === 0) return true;
            return false;
        }
        return true;
    }

    for (let i = n - 2; i >= 0; i--) {
        for (let j = i + 1; j < n; j++) {
            let newChar = s[j];
            if (helper(s.slice(i, j + 1), newChar)) dp[i][j] = dp[i][j - 1] + 1;
            else dp[i][j] = dp[i][j];
        }
    }

    return dp[0][n - 1];
}

let charList = ['a', 'b', 'C'],
    s = "axabybbbC";

console.log(maxSubStrLength(charList, s));